package com.zaofan.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

import com.zaofan.bean.OpenArea;
import com.zaofan.bean.OpenCity;
import com.zaofan.constant.StateConstant;
import com.zaofan.dao.base.DaoSupportImpl;

public class OpenAreaDao extends DaoSupportImpl<OpenArea> {

	public void updateCityName(OpenCity city) {
		try {
			String sql = "update " + OpenArea.class.getSimpleName().toLowerCase() + " set cityName = '"
					+ city.getCityName() + "' where cityId = " + city.getId();
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			runner.update(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updateState(OpenArea area) {
		try {
			String sql = "update " + OpenArea.class.getSimpleName().toLowerCase() + " set state = " + area.getState()
					+ " where id = " + area.getId();
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			runner.update(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updateStateUnShowByCityId(int cityId) {
		try {
			String sql = "update " + OpenArea.class.getSimpleName().toLowerCase() + " set state = "
					+ StateConstant.STATE_UN_SHOW + " where cityId = " + cityId;
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			runner.update(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
